using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class BaseCap : MonoBehaviour
{
    private Vector3 capPos0;
    private Quaternion capRot0;
    void Start()
    {
        capPos0 = transform.position;
        capRot0 = transform.rotation;
    }

    void OnEnable()
    {
        MyEventsManager.instance.capEvents.OnEndOfConveyor += ResetPosition;
    }
    void OnDisEnable()
    {
        MyEventsManager.instance.capEvents.OnEndOfConveyor -= ResetPosition;
    }
    private void ResetPosition()
    {
        transform.SetParent(null);
        transform.position = capPos0;
        transform.rotation = capRot0;
    }
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.name == "bottle")
            transform.SetParent(other.transform);
    }
}
